package com.medical.project.system.controller;

import java.util.List;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.medical.framework.aspectj.lang.annotation.Log;
import com.medical.framework.aspectj.lang.enums.BusinessType;
import com.medical.project.system.domain.Policy;
import com.medical.project.system.service.IPolicyService;
import com.medical.framework.web.controller.BaseController;
import com.medical.framework.web.domain.AjaxResult;
import com.medical.common.utils.poi.ExcelUtil;
import com.medical.framework.web.page.TableDataInfo;

/**
 * 慢性政策管理Controller
 *
 * @author tale
 * @date 2020-06-16
 */
@RestController
@RequestMapping("/system/policy")
public class PolicyController extends BaseController {
    @Autowired
    private IPolicyService policyService;

    /**
     * 查询慢性政策管理列表
     */
//    @PreAuthorize("@ss.hasPermi('system:policy:list')")
    @GetMapping("/list")
    public TableDataInfo list(Policy policy) {
        startPage();
        List<Policy> list = policyService.selectPolicyList(policy);
        return getDataTable(list);
    }

    /**
     * 导出慢性政策管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:policy:export')")
    @Log(title = "慢性政策管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Policy policy) {
        List<Policy> list = policyService.selectPolicyList(policy);
        ExcelUtil<Policy> util = new ExcelUtil<Policy>(Policy.class);
        return util.exportExcel(list, "policy");
    }

    /**
     * 获取慢性政策管理详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:policy:query')")
    @GetMapping(value = "/{year}")
    public AjaxResult getInfo(@PathVariable("year") Long year) {
        return AjaxResult.success(policyService.selectPolicyById(year));
    }

    /**
     * 新增慢性政策管理
     */
    @PreAuthorize("@ss.hasPermi('system:policy:add')")
    @Log(title = "慢性政策管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Policy policy) {
        return toAjax(policyService.insertPolicy(policy));
    }

    /**
     * 修改慢性政策管理
     */
    @PreAuthorize("@ss.hasPermi('system:policy:edit')")
    @Log(title = "慢性政策管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Policy policy) {
        return toAjax(policyService.updatePolicy(policy));
    }

    /**
     * 删除慢性政策管理
     */
    @PreAuthorize("@ss.hasPermi('system:policy:remove')")
    @Log(title = "慢性政策管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(policyService.deletePolicyByIds(ids));
    }
}
